package com.ruoyi.storeIndex.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.storeIndex.domain.StoreOrder;
import com.ruoyi.storeIndex.service.IStoreOrderStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/storeIndex/storeOrder")
public class StoreOrderStatisticsController extends BaseController {
    @Autowired
    private IStoreOrderStatisticsService storeOrderStatisticsService;


    /**
     * 商户首页被调订单图
     * @param startTimeStr
     * @param endTimeStr
     * @return
     * @throws ParseException
     */
    @GetMapping("/getStoreOrder")
    public AjaxResult getStoreOrder(@RequestParam(value = "startTime") String startTimeStr, @RequestParam(value = "endTime") String endTimeStr) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date startTime = sdf.parse(startTimeStr);
        Date endTime = sdf.parse(endTimeStr);

        Long deptId = SecurityUtils.getDeptId();
        Map<String, List<StoreOrder>> map = new HashMap<>();
        List<StoreOrder> list = storeOrderStatisticsService.getStoreOrder(startTime,endTime,deptId);
        map.put("list",list);
        return AjaxResult.success(map);
    }
}
